//
//  KLNoValueView.m
//  WisdomFamilyDoctor
//
//  Created by jinglian on 16/6/13.
//  Copyright © 2016年 kinglian. All rights reserved.
//

#import "KLNoValueView.h"

@interface KLNoValueView ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *defaultImageView;
@property (weak, nonatomic) IBOutlet UIButton *opeButton;
/** 按钮高度, 默认0且隐藏, 当显示的时候是25 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonLayoutHeight;
/** 按钮上部margin, 默认0, 按钮显示的时候是10 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *buttonLayoutTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *containterLayoutOffY;

@end

@implementation KLNoValueView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.autoresizingMask = UIViewAutoresizingNone;
    
    self.buttonLayoutHeight.constant = 0;
    self.buttonLayoutTop.constant = 0;
    
    self.opeButton.app_touchExtendInset = UIEdgeInsetsMake(-10, -20, -10, -20);
    [self.opeButton addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
}

+ (instancetype)noValueView {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
}
 
- (void)setNoValueTip:(NSString *)noValueTip {
    _noValueTip = noValueTip;
    
    self.titleLabel.text = noValueTip;
}

- (void)setDefaultImg:(UIImage *)defaultImg {
    if (defaultImg != nil) {
        _defaultImg = defaultImg;
        self.defaultImageView.image = defaultImg;
    }
}

- (void)setCenterOffY:(CGFloat)centerOffY {
    _centerOffY = centerOffY;
    
    self.containterLayoutOffY.constant = centerOffY;
    
    [self layoutIfNeeded];
}

- (void)showButtonWithTitle:(NSString *)title state:(UIControlState)state {
    if ([NSString app_isBlankString:title]) {
        NSLog(@"请传入正确的按钮参数");
        return;
    }
    
    self.buttonLayoutHeight.constant = 25.f;
    self.buttonLayoutTop.constant = 10;
    
    self.opeButton.hidden = NO;
    [self.opeButton setTitle:title forState:state];
    
    [self layoutIfNeeded];
}

- (void)btnClick {
    if (self.novalueBtnClick) {
        self.novalueBtnClick();
    }
}

@end
